/*
*  Copyright 2019-2025 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import me.zhengjie.pojo.dto.WcsInboundMissionHistoryQueryCriteria;
import me.zhengjie.pojo.entity.WcsInboundMissionHistory;
import me.zhengjie.pojo.vo.ReturnVo;
import me.zhengjie.sqlservice.WcsInboundMissionHistorySqlService;
import me.zhengjie.utils.PageResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
* @author zhixiao
* @date 2025-06-28
**/
@RestController
@RequiredArgsConstructor
//@Api(tags = "inboundTaskHistory")
@RequestMapping("/wcs/wcsInboundMissionHistory")
public class WcsInboundMissionHistoryController {

    private final WcsInboundMissionHistorySqlService wcsInboundMissionHistoryService;

    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
//    @PreAuthorize("@el.check('wcsInboundMissionHistory:list')")
    public void exportWcsInboundMissionHistory(HttpServletResponse response, WcsInboundMissionHistoryQueryCriteria criteria) throws IOException {
        wcsInboundMissionHistoryService.download(wcsInboundMissionHistoryService.queryAll(criteria), response);
    }

    @GetMapping
    @ApiOperation("查询inboundTaskHistory")
//    @PreAuthorize("@el.check('wcsInboundMissionHistory:list')")
    public ResponseEntity<PageResult<WcsInboundMissionHistory>> queryWcsInboundMissionHistory(WcsInboundMissionHistoryQueryCriteria criteria){
        Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
        return new ResponseEntity<>(wcsInboundMissionHistoryService.queryAll(criteria,page),HttpStatus.OK);
    }

    @PostMapping
//    @Log("新增inboundTaskHistory")
    @ApiOperation("新增inboundTaskHistory")
//    @PreAuthorize("@el.check('wcsInboundMissionHistory:add')")
    public ResponseEntity<Object> createWcsInboundMissionHistory(@Validated @RequestBody WcsInboundMissionHistory resources){
        wcsInboundMissionHistoryService.create(resources);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @PutMapping
//    @Log("修改inboundTaskHistory")
    @ApiOperation("修改inboundTaskHistory")
//    @PreAuthorize("@el.check('wcsInboundMissionHistory:edit')")
    public ResponseEntity<Object> updateWcsInboundMissionHistory(@Validated @RequestBody WcsInboundMissionHistory resources){
        wcsInboundMissionHistoryService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
//    @Log("删除inboundTaskHistory")
    @ApiOperation("删除inboundTaskHistory")
//    @PreAuthorize("@el.check('wcsInboundMissionHistory:del')")
    public ResponseEntity<Object> deleteWcsInboundMissionHistory(@ApiParam(value = "传ID数组[]") @RequestBody List<Long> ids) {
        wcsInboundMissionHistoryService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @ApiOperation(("入库历史任务明细查询"))
    @GetMapping("/query")
    public ReturnVo inboundHistoryMission(@RequestParam(defaultValue = "")String inboundCode){
        ReturnVo returnVo = wcsInboundMissionHistoryService.inboudHistoryMission(inboundCode);
        return returnVo;
    }
}